package cn.xiaopengstack.domain.activity.service.quota.policy.impl;

import cn.xiaopengstack.domain.activity.model.aggregate.CreateRechangeQuotaOrderAggregate;
import cn.xiaopengstack.domain.activity.model.valobj.OrderStateVO;
import cn.xiaopengstack.domain.activity.repository.IRaffleActivityRepository;
import cn.xiaopengstack.domain.activity.service.quota.policy.IRechargePolicy;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author jiangyangang
 * @see cn.xiaopengstack.domain.activity.model.valobj.RechangeTypeVO
 */
@Service("credit_exchange_rechange")
public class CreditExchangeRechargePolicy implements IRechargePolicy {

    @Resource
    private IRaffleActivityRepository raffleActivityRepository;

    @Override
    public void doRechange(CreateRechangeQuotaOrderAggregate aggregate) {
        aggregate.getRaffleActivityOrderEntity().setState(OrderStateVO.wait_pay);
        aggregate.getRaffleActivityOrderEntity().setPayAmount(aggregate.getSkuEntity().getProductAmount());

        // 保存订单
        raffleActivityRepository.saveCreditExchangeOrder(aggregate);
    }
}
